package solutions.leetcode.easy;

import solutions.lib.BaseSolution;
import solutions.lib.TreeNode;

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/binary-tree-preorder-traversal/">144. 二叉树的前序遍历</a>
 */
public class Solution144 extends BaseSolution {

    public List<Integer> preorderTraversal(TreeNode root) {
        List<Integer> list = new LinkedList<>();
        check(root, list);
        return list;
    }

    private void check(TreeNode node, List<Integer> list) {
        if (node == null) {
            return;
        }
        list.add(node.val);
        check(node.left, list);
        check(node.right, list);
    }

    public static void main(String[] args) {
        Solution144 solution = new Solution144();
    }
}